package top.jacktgq.oop

/**
 @Author CandyWall
 @Date 2021/4/27--20:07
 @Description groovy面向对象编程：
                1. groovy中默认都是public
 */
class Person implements Action, DefaultAction, Serializable {
    String name
    Integer age

    def increaseAge(Integer years) {
        this.age += years
    }

    String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    /**
     * 调用该类的一个对象的不存在的方法时，会调用该方法代替
     * @param name
     * @param args
     * @return
     */
    def methodMissing(String name, def args) {
        return "Call methodMissing! The method is ${name}, the params are ${args}"
    }

    @Override
    /**
     * 调用该类的一个对象的不存在的方法时，会先调用methodMissing，当methodMissing不存在时，会调用该方法代替
     */
    Object invokeMethod(String name, Object args) {
        return "Call invokeMethod! The method is ${name}, the params are ${args}"
    }

    @Override
    void eat() {

    }

    @Override
    void drink() {

    }

    @Override
    void play() {

    }
}
